package com.gwcslife.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@SpringBootApplication
@EnableDiscoveryClient
public class GatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }

    //java配置方式
    @Bean
    public RouteLocator setRouteLocator(RouteLocatorBuilder routeLocatorBuilder){
        System.out.println("route...");
        return routeLocatorBuilder.routes()
                .route("insurance",r-> r.path("/insurance/**")
                        .uri("lb://insuranceService"))
                .route("policy",p -> p.path("/policy/**")
                        .uri("lb://policyService")
                )
                .build();
    }
}
